package cn.sylinx.horm.example.section7;

import java.util.HashMap;
import java.util.List;

import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import cn.sylinx.horm.core.SqlClient;
import cn.sylinx.horm.resource.ClasspathSqlResource;

@Profile("section7")
@Component
public class Section7 implements CommandLineRunner {

    private SqlClient sqlClient;
    private MyExample7Command myExample7Command;

    public Section7(SqlClient sqlClient, MyExample7Command myExample7Command) {
        this.sqlClient = sqlClient;
        this.myExample7Command = myExample7Command;
    }

    @Override
    public void run(String... args) throws Exception {
        testSqlClientInterceptor1();
        testSqlClientInterceptor2();
        testCommandInterceptor1();
        testCommandInterceptor2();
    }

    void testSqlClientInterceptor1() {

        List<MyExample7> dataList = sqlClient.queryList(
                ClasspathSqlResource.applySystemResource("horm/system/testExample7.sql"), null, MyExample7.class);
        System.out.println(dataList);
        System.out.println("-----------");
        System.out.println();
    }

    void testSqlClientInterceptor2() {

        // 该方法不会被拦截
        MyExample7 data = sqlClient.queryFirst(ClasspathSqlResource.applySystemResource("horm/system/testExample7.sql"),
                new HashMap<>(), MyExample7.class);
        System.out.println(data);
        System.out.println("-----------");
        System.out.println();
    }

    void testCommandInterceptor1() {
        List<MyExample7> dataList = myExample7Command.queryList(null);
        System.out.println(dataList);
        System.out.println("-----------");
        System.out.println();
    }

    void testCommandInterceptor2() {
        MyExample7 data = myExample7Command.queryOne(null);
        System.out.println(data);
        System.out.println("-----------");
        System.out.println();
    }
}
